/**
 * 
 */
package com.oot.twitter.info;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * @author luckymancvp
 *
 */
public class Tweet {
	private String tweet_id, content, created_time, parent_id, user_id, username, full_name, avatar, refav, retweeted_by;
	private boolean isFavorited = false, isRetweeted = false;

	public String getTweet_id() {
		return tweet_id;
	}

	public void setTweet_id(String tweet_id) {
		this.tweet_id = tweet_id;
	}

	public String getUser_id() {
		return user_id;
	}

	public void setUser_id(String user_id) {
		this.user_id = user_id;
	}

	public String getRefav() {
		return refav;
	}

	public void setRefav(String refav) {
		this.refav = refav;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getCreated_time() {
		return created_time;
	}

	public void setCreated_time(String created_time) {
		this.created_time = created_time;
	}

	public String getParent_id() {
		return parent_id;
	}

	public void setParent_id(String parent_id) {
		this.parent_id = parent_id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getFull_name() {
		return full_name;
	}

	public void setFull_name(String full_name) {
		this.full_name = full_name;
	}

	public String getAvatar() {
		return avatar;
	}

	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}

	public boolean isFavorited() {
		return isFavorited;
	}

	public void setFavorited(boolean isFavorited) {
		this.isFavorited = isFavorited;
	}

	public boolean isRetweeted() {
		return isRetweeted;
	}

	public void setRetweeted(boolean isRetweeted) {
		this.isRetweeted = isRetweeted;
	}

    public  Tweet(){

    }

	public Tweet(String jsonString){
	}
	
	public Tweet(JSONObject jsonObject){
		TJSonParser parser = new TJSonParser(jsonObject);

		tweet_id     = parser.getString("tweet_id","");
		content      = parser.getString("content","");
		parent_id    = parser.getString("parent_id","");
		created_time = parser.getString("created_time","");
		user_id      = parser.getString("user_id","");
		full_name    = parser.getString("full_name","");
		username     = parser.getString("username","");
		avatar       = parser.getString("avatar","");
		retweeted_by = parser.getString("retweeted_by","");
		refav        = parser.getString("refav","0");

		// Calc favorite and retweet value
		try{
			int refavVal = Integer.parseInt(refav);
			if (refavVal % 10 == 1) isRetweeted = true;
			if (refavVal / 10 == 1) isFavorited = true;
		}catch (Exception e){
			System.out.println("Error in calc refav");
			isRetweeted = false;
			isFavorited = false;
		}
	}

    public static ArrayList<Tweet> parseArray(JSONArray jsonArray){
        ArrayList<Tweet> tweets = new ArrayList<Tweet>();
        try{
            for (int i=0 ; i< jsonArray.length(); i++)
                tweets.add(new Tweet((JSONObject)jsonArray.get(i)));
        }catch (Exception e){
            System.out.println("Error in parse json array");
        }
        return tweets;
    }
}
